package org.esprit.ocm.client.ui.common;

import org.esprit.ocm.dto.impl.UserDto;

import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class HeaderArea extends HLayout {

	private static final int	HEADER_AREA_HEIGHT	= 50;

	public HeaderArea(final UserDto u) {

		super();

		this.setHeight(HEADER_AREA_HEIGHT);

		Img logo = new Img("banner2.png", 387, 80);

		HLayout westLayout = new HLayout();
		westLayout.setHeight(HEADER_AREA_HEIGHT);
		westLayout.setWidth("50%");
		westLayout.addMember(logo);

		Label logoutLabel = new Label("<b>Sign Out<b>");
		logoutLabel.setWidth(60);

		ImgButton logoutButton = new ImgButton();
		logoutButton.setSrc("signout.png");
		logoutButton.setHeight(64);
		logoutButton.setWidth(64);
		logoutButton.setShowRollOver(false);
		logoutButton.setShowDown(true);
		logoutButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				RootLayoutPanel.get().clear();

				Login loginWindow = new Login();
				loginWindow.show();
			}
		});

		Label exchangeServerLabel = new Label("<b>Switch to another cloud server<b>");
		exchangeServerLabel.setWidth(100);

		ImgButton exchangeServerButton = new ImgButton();
		exchangeServerButton.setSrc("switch.png");
		exchangeServerButton.setHeight(65);
		exchangeServerButton.setWidth(90);
		exchangeServerButton.setTop(30);
		exchangeServerButton.setShowRollOver(false);
		exchangeServerButton.setShowDown(true);
		exchangeServerButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				ServerWindow serverWindow = new ServerWindow(u);
				serverWindow.show();
				serverWindow.setShowCloseButton(true);
			}
		});

		HLayout eastLayout = new HLayout();
		eastLayout.setAlign(Alignment.RIGHT);
		eastLayout.setHeight(HEADER_AREA_HEIGHT);
		eastLayout.setWidth("50%");

		HLayout changeServerLayout = new HLayout();
		changeServerLayout.setHeight(HEADER_AREA_HEIGHT);
		changeServerLayout.setWidth("50%");
		changeServerLayout.addMember(exchangeServerLabel);
		changeServerLayout.addMember(exchangeServerButton);

		HLayout logoutLayout = new HLayout();
		logoutLayout.setHeight(HEADER_AREA_HEIGHT);
		logoutLayout.setAlign(Alignment.RIGHT);
		logoutLayout.setWidth("50%");
		logoutLayout.addMember(logoutButton);
		logoutLayout.addMember(logoutLabel);

		eastLayout.addMember(changeServerLayout);
		eastLayout.addMember(logoutLayout);

		this.addMember(westLayout);
		this.addMember(eastLayout);

	}

}
